package com.huihui.activity.setting;

import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.huihui.R;
import com.huihui.base.BaseActivity;
import com.huihui.datamanager.AppManager;
import com.huihui.network.HttpContants;
import com.huihui.network.OkHttpRequest;
import com.huihui.network.base.CallBackUtil;
import com.huihui.widget.MyRadioGroup;

import okhttp3.Call;
import okhttp3.Response;

public class ReportAnswerActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener{

    private TextView title;
    private TextView content;
    private RadioButton bt1;
    private RadioButton bt3;
    private RadioButton bt4;
    private RadioButton bt5;
    private RadioButton bt6;
    private TextView report;
    private long beReport_user_id;
    private long current_report_content_id;
    private int class_id;
    private String contentStr;
    private String username;
    private MyRadioGroup myRadioGroup;
    private int type=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report_answer);
        titleView.setText(R.string.report);
        initView();
        initData();
        initListener();
    }


    private void initData() {
        username = getIntent().getStringExtra("username");
        beReport_user_id = getIntent().getLongExtra("beReport_user_id",0);
        current_report_content_id = getIntent().getLongExtra("current_report_content_id",0);
        class_id = getIntent().getIntExtra("class_id",0);
        contentStr = getIntent().getStringExtra("content");
        String str = "";
        if(class_id == 1){
            str = "举报"+ username+"的评论:";
        }else if (class_id == 4){
            str = "举报"+ username+"的评论:";
        }
        String str2 = username+ ":" + contentStr;

        SpannableString spannableString = new SpannableString(str);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#feba54")), 2,username.length() + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        title.setText(spannableString);

        SpannableString spannableString1 = new SpannableString(str2);
        spannableString1.setSpan(new ForegroundColorSpan(Color.parseColor("#feba54")), 0,username.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        content.setText(spannableString1);

    }

    private void initListener() {
        myRadioGroup.setOnCheckedChangeListener(this);// 当然也可以使用匿名内部类实现
        report.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doReport();
            }
        });
    }

    private void doReport() {
        if(type == 0){
            return;
        }
        OkHttpRequest.getInstance().doReport(HttpContants.addReport, AppManager.getUserInfo().getUser_id(), beReport_user_id, "", current_report_content_id, type, class_id, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {
                Log.e("","");
            }

            @Override
            public void onResponse(String response) {
                finish();
            }
        });
    }

    private void initView() {
        title = findViewById(R.id.title);
        content = findViewById(R.id.content);
        myRadioGroup = findViewById(R.id.myRadioGroup);
        bt1 = findViewById(R.id.bt1);
        bt3 = findViewById(R.id.bt3);
        bt4 = findViewById(R.id.bt4);
        bt5 = findViewById(R.id.bt5);
        bt6 = findViewById(R.id.bt6);
        report = findViewById(R.id.report);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.bt1:
                type = 1;
                break;
            case R.id.bt2:
                type = 2;
                break;
            case R.id.bt3:
                type = 3;
                break;
            case R.id.bt4:
                type = 4;
                break;
            case R.id.bt5:
                type = 5;
                break;
            case R.id.bt6:
                type = 6;
                break;
            case R.id.bt7:
                type = 7;
                break;
        }
    }
}
